<template>
  <div id="login">
    <h1>调用微信 </h1>
    <button @click="getdata()">这是一个普通的接口</button>
    <button @click="getdata2()">这个maindef跟之前不太一样</button>
    <br />
    <button @click="getwxcod()">个人信息接口:</button>
    <button></button>
  </div>
</template>
<script>
import jwt_decode from "jwt-decode";
export default {
  name: "login",
  data() {
    return {};
  },
  created() {},
  methods: {
    getwxcod() {
      let wx = {
        appid: "ww3577a1f12685dd23",
        redirect_uri: "http://154.209.5.28:4000",
        state: "", //可不填写
        corpid: "ww3577a1f12685dd23",
        corpsecret: "GN2RAsEKy1Wx9_lKdw-ZYLwfsCiFmz319C3a2VS-maU",
        access_token: ""
      };
      function encodeURI(x) {
        return encodeURIComponent(x.toString()).toLowerCase();
      }
      let url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${
        wx.appid
      }&redirect_uri=${encodeURI(
        wx.redirect_uri
      )}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect`;
      console.log(url);
      this.$axios
        .get(url)
        .then(res => {
          console.log(res + "这是授权链接");
        })
        .catch(error => {});
      //@获取access_token
      //请求方式： GET（HTTPS）
      //请求地址： https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=ID&corpsecret=SECRET
      this.$axios(
        `https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=${wx.corpid}&corpsecret=${wx.corpsecret}`
      ).then(res => {
        console.log(res + "这是access_token");
      });
      //获取访问用户身份成员信息
      //请求方式：GET（HTTPS）
      //请求地址：https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token=ACCESS_TOKEN&code=CODE
      //参数说明：、
      this.$axios
        .get(
          `https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token=${wx.access_token}&code=CODE`
        )
        .then(res => {
          console.log("用户的账户");
        });
    },
    getdata(){
      this.$axios.get('/json').then(res=>{
        console.log(res.data)
      })
    },
    getdata2(){
      this.$axios.get({
        url

      }).then(res=>{
        alert(res.data)
      })
    }
  }
};
</script>

<style scoped>
#login {
  width: 100%;
  height: 100%;
}
</style>


